package com.callbox.dao;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;

import com.callbox.entity.*;

public class ClsMessageDAO {
	
	private final String MESSAGE_TABLE = "Message";
	
	private static ClsMessageDAO instance = null;	
	public static ClsMessageDAO Instance() {		
		if(instance == null){
			instance = new ClsMessageDAO();
		}		
		return instance;
	}
	
	public List<ClsMessage> ListByMobile(Context context, int IdMobile ) {
		
		ArrayList<ClsMessage> ListMessages = new ArrayList<ClsMessage>();
		
		String[] cols = new String[] { "_Id"," ReceiptDate"};
		
		SqliteHelper Connection = ClsConnection.GetSqliteAcces(context);
		Connection.open();		
		Cursor result = 
				Connection.Database().query(MESSAGE_TABLE,cols, null, null, null, null, String.valueOf(IdMobile));
		
		if (result.moveToFirst())
			do {
				ClsMessage objMessage = new ClsMessage();
				objMessage.setId(result.getInt(result.getColumnIndex(cols[0])));
				objMessage.setReceiptDate(result.getString(result.getColumnIndex(cols[1])));
				ListMessages.add(objMessage);
				
			} while(result.moveToNext());
		
		return ListMessages;
	}
	

}
